home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / -archivi / -recent1 / nsm_tnw041b.lha / tracknameswindow / windowcontrol.c < prev    next >
C/C++ Source or Header  |  1999-02-21  |  8KB  |  301 lines

  1. /*
  2.  *  Source machine generated by GadToolsBox V2.0b
  3.  *  which is (c) Copyright 1991-1993 Jaba Development
  4.  *  (The generated source is changed completely. -KSM.)
  5.  *
  6.  *  GUI Designed by : Kjetil S. Matheussen
  7.  
  8.  
  9.     Various graphic.library and intuition.library specific
  10.     functions needed for the tracknameswindow.
  11.  
  12.     Made by Kjetil S. Matheussen 1998.
  13.  
  14.  */
  15.  
  16. #include <exec/types.h>
  17. #include <intuition/intuition.h>
  18. #include <intuition/classes.h>
  19. #include <intuition/classusr.h>
  20. #include <intuition/imageclass.h>
  21. #include <intuition/gadgetclass.h>
  22. #include <libraries/gadtools.h>
  23. #include <graphics/displayinfo.h>
  24. #include <graphics/gfxbase.h>
  25. #include <clib/exec_protos.h>
  26. #include <clib/intuition_protos.h>
  27. #include <clib/gadtools_protos.h>
  28. #include <clib/graphics_protos.h>
  29. #include <clib/utility_protos.h>
  30. #include <string.h>
  31. #include <stdio.h>
  32.  
  33. #include "windowcontrol.h"
  34.  
  35. struct Screen         *Scr = NULL;
  36. UBYTE                 *PubScreenName = "OCTAMED";
  37. APTR                   VisualInfo = NULL;
  38. struct Window         *tnmWnd = NULL;
  39. UWORD                  tnmLeft;
  40. UWORD                  tnmTop;
  41. UWORD                  tnmWidth;
  42. UWORD                  tnmHeight;
  43. UBYTE                 *tnmWdt = (UBYTE *)"01:";
  44.  
  45. extern int ypos;
  46. extern char *editorfontname;
  47. extern int editorfontsize;
  48. extern int windowheight;
  49. extern int topmarkcursorpos,botmarkcursorpos;
  50. extern int fontpos;
  51. extern int whitelinetop,whitelinebot;
  52.  
  53. int SetupScreen( void )
  54. {
  55.     if ( ! ( Scr = LockPubScreen( PubScreenName )))
  56.         return( 1L );
  57.  
  58.     if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
  59.         return( 2L );
  60.  
  61.     return( 0L );
  62. }
  63.  
  64. void CloseDownScreen( void )
  65. {
  66.     if ( VisualInfo ) {
  67.         FreeVisualInfo( VisualInfo );
  68.         VisualInfo = NULL;
  69.     }
  70.  
  71.     if ( Scr        ) {
  72.         UnlockPubScreen( NULL, Scr );
  73.         Scr = NULL;
  74.     }
  75. }
  76.  
  77.  
  78. int OpentnmWindow( void )
  79. {
  80.     UWORD offy = Scr->WBorTop + Scr->RastPort.TxHeight + 1;
  81.  
  82.     if ( ! ( tnmWnd = OpenWindowTags( NULL,
  83.                 WA_Left,    tnmLeft,
  84.                 WA_Top,        tnmTop,
  85.                 WA_Width,    tnmWidth,
  86.                 WA_Height,    tnmHeight + offy,
  87.                 WA_IDCMP,    IDCMP_REFRESHWINDOW,
  88.                 WA_Flags,    WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_SMART_REFRESH,
  89.                 WA_Title,    tnmWdt,
  90.                 WA_ScreenTitle,    "Tracknamewindow for Octamed SS 1.03c. Made by Kjetil S. Matheussen 1999.",
  91.                 WA_PubScreen,    Scr,
  92.                 TAG_DONE )))
  93.     return( 4L );
  94.  
  95.     GT_RefreshWindow( tnmWnd, NULL );
  96.  
  97.  
  98.     return( 0L );
  99. }
  100.  
  101. void ClosetnmWindow( void )
  102. {
  103.     if ( tnmWnd        ) {
  104.         CloseWindow( tnmWnd );
  105.         tnmWnd = NULL;
  106.     }
  107. }
  108.  
  109. struct TextFont *mytextfont;
  110. UWORD fontsize;
  111. UWORD screenfontsize;
  112.  
  113. int numvisibletracks;
  114. int currvisibletrack=0;
  115.  
  116. int namewidth,startwidth;
  117.  
  118. void drawwhite(void){
  119.     int lokke;
  120.     SetAPen(tnmWnd->RPort,2);
  121.  
  122.     Move( tnmWnd->RPort, startwidth, whitelinetop);
  123.     Draw( tnmWnd->RPort, startwidth, whitelinebot);
  124.  
  125.     Move( tnmWnd->RPort, startwidth+1, whitelinetop);
  126.     Draw( tnmWnd->RPort, startwidth+1, whitelinebot);
  127.  
  128.     for(lokke=1;lokke<=numvisibletracks;lokke++){
  129.         Move( tnmWnd->RPort, lokke*namewidth+startwidth, whitelinetop);
  130.         Draw( tnmWnd->RPort, lokke*namewidth+startwidth, whitelinebot);
  131.  
  132.         Move( tnmWnd->RPort, lokke*namewidth+1+startwidth, whitelinetop);
  133.         Draw( tnmWnd->RPort, lokke*namewidth+1+startwidth, whitelinebot);
  134.     }
  135. }
  136.  
  137. void inserttext(char *trackname,int pos,int pen){
  138.     SetAPen(tnmWnd->RPort,1);
  139.     SetBPen(tnmWnd->RPort,pen);
  140.     Move(tnmWnd->RPort,startwidth+(namewidth*pos)+(startwidth/8)+1,fontpos);
  141.     Text(tnmWnd->RPort,trackname,9);
  142. }
  143.  
  144.  
  145. void drawvisibletrack(int pos,int pen){
  146.     SetAPen(tnmWnd->RPort,pen);
  147.  
  148.     Move(tnmWnd->RPort,startwidth+(namewidth*pos)+2,topmarkcursorpos);
  149.     Draw(tnmWnd->RPort,startwidth+(namewidth*(pos+1))-2,topmarkcursorpos);
  150.     Move(tnmWnd->RPort,startwidth+(namewidth*pos)+2,topmarkcursorpos+1);
  151.     Draw(tnmWnd->RPort,startwidth+(namewidth*(pos+1))-2,topmarkcursorpos+1);
  152.  
  153.     Move(tnmWnd->RPort,startwidth+(namewidth*pos)+2,botmarkcursorpos);
  154.     Draw(tnmWnd->RPort,startwidth+(namewidth*(pos+1))-2,botmarkcursorpos);
  155.     Move(tnmWnd->RPort,startwidth+(namewidth*pos)+2,botmarkcursorpos+1);
  156.     Draw(tnmWnd->RPort,startwidth+(namewidth*(pos+1))-2,botmarkcursorpos+1);
  157. }
  158.  
  159. void movecursorleft(void){
  160.     if(currvisibletrack<numvisibletracks-1){
  161.         drawvisibletrack(currvisibletrack,0);
  162.         currvisibletrack++;
  163.         drawvisibletrack(currvisibletrack,1);
  164.     }
  165. }
  166.  
  167. void movecursorright(void){
  168.     if(currvisibletrack>0){
  169.         drawvisibletrack(currvisibletrack,0);
  170.         currvisibletrack--;
  171.         drawvisibletrack(currvisibletrack,1);
  172.     }
  173. }
  174.  
  175. void scrollleft(void){
  176.     ScrollRaster(
  177.         tnmWnd->RPort,
  178.         namewidth,0,
  179.         startwidth,topmarkcursorpos+3,
  180.         numvisibletracks*namewidth+startwidth-1,botmarkcursorpos-2
  181.     );
  182.  
  183.     SetAPen(tnmWnd->RPort,2);
  184.     Move( tnmWnd->RPort,(numvisibletracks-1)*namewidth+startwidth, whitelinetop); 
  185.     Draw(tnmWnd->RPort,(numvisibletracks-1)*namewidth+startwidth, whitelinebot);
  186.     Move( tnmWnd->RPort,(numvisibletracks-1)*namewidth+startwidth+1, whitelinetop); 
  187.     Draw(tnmWnd->RPort,(numvisibletracks-1)*namewidth+startwidth+1, whitelinebot);
  188.  
  189.     SetAPen(tnmWnd->RPort,0);
  190.     Move( tnmWnd->RPort,(numvisibletracks-1)*namewidth+startwidth+2, whitelinetop); 
  191.     Draw(tnmWnd->RPort,(numvisibletracks-1)*namewidth+startwidth+2, whitelinebot);
  192.     Move( tnmWnd->RPort,(numvisibletracks-1)*namewidth+startwidth+3, whitelinetop); 
  193.     Draw(tnmWnd->RPort,(numvisibletracks-1)*namewidth+startwidth+3, whitelinebot);
  194.  
  195.     Move( tnmWnd->RPort,(numvisibletracks)*namewidth+startwidth-1, whitelinetop); 
  196.     Draw(tnmWnd->RPort,(numvisibletracks)*namewidth+startwidth-1, whitelinebot);
  197.     Move( tnmWnd->RPort,(numvisibletracks)*namewidth+startwidth-2, whitelinetop); 
  198.     Draw(tnmWnd->RPort,(numvisibletracks)*namewidth+startwidth-2, whitelinebot);
  199.  
  200.  
  201.  
  202. }
  203.  
  204. void scrollright(void){
  205.     ScrollRaster(
  206.         tnmWnd->RPort,
  207.         -namewidth,0,
  208.         startwidth+4,topmarkcursorpos+3,
  209.         numvisibletracks*namewidth+startwidth,botmarkcursorpos-2
  210.     );
  211.  
  212.     SetAPen(tnmWnd->RPort,2);
  213.     Move( tnmWnd->RPort,namewidth+startwidth, whitelinetop); 
  214.     Draw(tnmWnd->RPort,namewidth+startwidth, whitelinebot);
  215.     Move( tnmWnd->RPort,namewidth+startwidth+1, whitelinetop); 
  216.     Draw(tnmWnd->RPort,namewidth+startwidth+1, whitelinebot);
  217.  
  218.     SetAPen(tnmWnd->RPort,0);
  219.     Move( tnmWnd->RPort,namewidth+startwidth+2, whitelinetop); 
  220.     Draw(tnmWnd->RPort,namewidth+startwidth+2, whitelinebot);
  221.     Move( tnmWnd->RPort,namewidth+startwidth+3, whitelinetop); 
  222.     Draw(tnmWnd->RPort,namewidth+startwidth+3, whitelinebot);
  223.  
  224.     Move( tnmWnd->RPort,namewidth+startwidth-1, whitelinetop); 
  225.     Draw(tnmWnd->RPort,namewidth+startwidth-1, whitelinebot);
  226.     Move( tnmWnd->RPort,namewidth+startwidth-2, whitelinetop); 
  227.     Draw(tnmWnd->RPort,namewidth+startwidth-2, whitelinebot);
  228.  
  229. }
  230.  
  231. void showinumname(char *name){
  232.     SetWindowTitles(tnmWnd,name,(UBYTE *)-1);
  233. }
  234.  
  235. struct TextAttr standardfontstruct={"topaz.font",8,0,0};
  236. struct TextAttr *fontstruct;
  237.  
  238. void initwindow(
  239.     char *editfontTextAttrstruct,
  240.     UWORD edittopleft,
  241.     UWORD editwidth,
  242.     int numvisibletrakks,
  243.     UWORD screenfontYsize
  244. )
  245. {
  246.     numvisibletracks=numvisibletrakks;
  247.  
  248.     screenfontsize=screenfontYsize;
  249.     if(screenfontsize==0) screenfontsize=8;
  250.  
  251.     if(*editorfontname==NULL){
  252.         fontstruct=(struct TextAttr *)editfontTextAttrstruct;
  253.         if(fontstruct==NULL) fontstruct=&standardfontstruct;
  254.     }else{
  255.         fontstruct=&standardfontstruct;
  256.         fontstruct->ta_Name=editorfontname;
  257.         fontstruct->ta_YSize=editorfontsize;
  258.     }
  259.  
  260.     fontsize=fontstruct->ta_YSize;
  261.  
  262.     tnmLeft = edittopleft;
  263.  
  264.     tnmTop = ypos; if(tnmTop==-1) tnmTop=10;
  265.  
  266.     tnmWidth = editwidth+22;
  267.  
  268.     if(windowheight==-1){
  269.         tnmHeight = fontsize+screenfontsize+2;
  270.     }else{
  271.         tnmHeight = windowheight;
  272.     }
  273.  
  274.     if(topmarkcursorpos==-1) topmarkcursorpos=screenfontsize+fontsize-4;
  275.  
  276.     if(botmarkcursorpos==-1) botmarkcursorpos=screenfontsize+8+fontsize;
  277.  
  278.     if(fontpos==-1) fontpos=screenfontsize+5+fontsize;
  279.  
  280.     if(whitelinetop==-1) whitelinetop=screenfontsize+3;
  281.  
  282.     if(whitelinebot==-1) whitelinebot=screenfontsize+(fontsize*2)+2;
  283.  
  284.     SetupScreen();
  285.     OpentnmWindow();
  286.  
  287.     mytextfont=OpenFont(fontstruct);
  288.     SetFont(tnmWnd->RPort,mytextfont);
  289.     SetDrMd(tnmWnd->RPort,JAM2);
  290.  
  291.     startwidth=TextLength(tnmWnd->RPort,"1234",4 );
  292.     namewidth=TextLength( tnmWnd->RPort,"123456789b",10 );
  293.     drawwhite();
  294. }
  295.  
  296. void shutdownwindow(void){
  297.     CloseFont(mytextfont);
  298.     ClosetnmWindow();
  299.     CloseDownScreen();
  300. }
  301.